﻿@{
    ViewData["Title"] = "AddEmployee";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>增加人员</h2>


<body>
    <form class="layui-form" action="">
        <table>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" id="employeeName" name="employeeName" style="width:400px" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>

                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">性别：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="employeeSex" id="employeeSex" value="1" title="男" checked>
                            <input type="radio" name="employeeSex" id="employeeSex" value="0" title="女">
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td>
                    <div>
                        <label class="layui-form-label">证件类型：</label>
                        <div class="layui-col-md6">
                            <select id="certificateId" name="certificateId">
                                <option value="">请选择</option>
                                <option value="身份证">身份证</option>
                                <option value="护照">护照</option>
                                <option value="军官证">军官证</option>
                                <option value="士兵证">士兵证</option>
                                <option value="港澳台往来通行证">港澳台往来通行证</option>
                                <option value="警官证">警官证</option>
                                <option value="外国人永久居住证">外国人永久居住证</option>
                                <option value="边民出入通行证">边民出入通行证</option>
                                <option value="其他">其他</option>
                            </select>
                        </div><br /><br /><br />
                    </div>
                </td>

                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系电话：</label>
                        <div class="layui-input-block">
                            <input type="text" id="employeePhone" name="employeePhone" style="width:400px" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">证件号码：</label>
                        <div class="layui-input-block">
                            <input type="text" id="idNumber" name="idNumber" style="width:400px" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>

                <td>
                    <div class="layui-form-item" id="area-picker4">
                        <div class="layui-form-label">户口所在地：</div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select id="province4" class="province-selector" lay-filter="province-4">
                                <option value="">--选择省--</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select id="city4" class="city-selector" lay-filter="city-4">
                                <option value="">--选择市--</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select id="county4" class="county-selector" lay-filter="county-4">
                                <option value="">--选择区--</option>
                            </select>
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td>
                    <!--单位 外键-->
                    <label class="layui-form-label">单位：</label>
                    <div class="layui-col-md6">
                        <select id="unitId" name="unitId" style="width:400px">
                            <option value="">请选择</option>
                        </select>
                    </div><br /><br /><br />
                </td>

                <td>
                    <label class="layui-form-label">员工状态：</label>
                    <div class="layui-col-md6">
                        <select id="employeeState" name="employeeState">
                            <option value="">请选择</option>
                            <option value="试用员工">试用员工</option>
                            <option value="在职员工">在职员工</option>
                            <option value="实习员工">实习员工</option>
                            <option value="临时工人">临时工人</option>
                            <option value="调职员工">调职员工</option>
                            <option value="专家顾问">专家顾问</option>
                            <option value="返聘人员">返聘人员</option>
                        </select>
                    </div><br /><br /><br />
                </td>
            </tr>

            <tr>
                <td>
                    <!--部门编号  外键-->
                    <label class="layui-form-label">部门：</label>
                    <div class="layui-col-md6">
                        <select id="departId" name="departId">
                            <option value="">请选择</option>
                        </select>
                    </div><br /><br /><br />
                </td>

                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">入职日期：</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline">
                                <input type="text" id="entryDate" name="entryDate" class="layui-input" placeholder="yyyy-MM-dd">
                            </div>
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">职务：</label>
                    <div class="layui-col-md6">
                        <select id="position" name="position">
                            <option value="">请选择</option>
                            <option value="总经理">总经理</option>
                            <option value="人力经理">人力经理</option>
                            <option value="采购经理">采购经理</option>
                            <option value="生产经理">生产经理</option>
                            <option value="销售经理">销售经理</option>
                            <option value="财务经理">财务经理</option>
                        </select>
                    </div><br /><br /><br />
                </td>

                <td>
                    <label class="layui-form-label">岗位：</label>
                    <div class="layui-col-md6">
                        <select id="office" name="office">
                            <option value="">请选择</option>
                            <option value="事业部总经理">事业部总经理</option>
                            <option value="单位人力经理">单位人力经理</option>
                            <option value="单位采购经理">单位采购经理</option>
                            <option value="单位生产经理">单位生产经理</option>
                            <option value="单位销售经理">单位销售经理</option>
                            <option value="单位财务经理">单位财务经理</option>
                        </select>
                    </div><br /><br /><br />
                </td>
            </tr>

            <tr>
                <td>
                    <label class="layui-form-label">人事级别：</label>
                    <div class="layui-col-md6">
                        <select id="personnelLevel" name="personnelLevel">
                            <option value="">请选择</option>
                            <option value="A1">A1</option>
                            <option value="A2">A2</option>
                            <option value="A3">A3</option>
                            <option value="B1">B1</option>
                            <option value="B2">B2</option>
                            <option value="B3">B3</option>
                            <option value="C1">C1</option>
                            <option value="C2">C2</option>
                            <option value="C3">C3</option>
                            <option value="D1">D1</option>
                            <option value="D2">D2</option>
                            <option value="D3">D3</option>
                        </select>
                    </div><br /><br /><br />
                </td>

                <td>
                    <!--角色编号  外键-->
                    <label class="layui-form-label">角色：</label>
                    <div class="layui-col-md6">
                        <select id="roleId" name="roleId">
                            <option value="">请选择</option>
                        </select>
                    </div><br /><br /><br />
                </td>
            </tr>
        </table>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script>
        //配置插件目录
        layui.config({
            base: '/mods/'
        });
        layui.use(['form', 'laydate', 'util', 'layarea', 'layer'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var $ = layui.$;
            var layarea = layui.layarea;
            var employeeform = {};

            //日期
            var laydate = layui.laydate;
            // 渲染
            laydate.render({
                elem: '#entryDate',
            });

            layarea.render({
                elem: '#area-picker4',
                change: function (res) {
                    //选择结果
                    console.log(res)
                    employeeform.location = null;
                    employeeform.location = res.province + ',' + res.city + ',' + res.county;
                    console.log($("#province4").val());
                }
            });

            // 自定义验证规则
            form.verify({
                pass: function (value) {
                    if (!/(.+){6,12}$/.test(value)) {
                        return '密码必须 6 到 12 位';
                    }
                }
            });

            // 提交事件
            form.on('submit(demo1)', function (data) {
                var field = data.field; // 获取表单字段值

                employeeform.employeeName = field.employeeName;
                employeeform.employeeSex = field.employeeSex;
                employeeform.certificateId = field.certificateId;
                employeeform.employeePhone = field.employeePhone;
                employeeform.idNumber = field.idNumber;

                employeeform.unitId = field.unitId;
                employeeform.employeeState = field.employeeState;
                employeeform.departId = field.departId;
                employeeform.entryDate = field.entryDate;
                employeeform.position = field.position;
                employeeform.office = field.office;
                employeeform.personnelLevel = field.personnelLevel;
                employeeform.roleId = field.roleId;

                $.ajax({
                        //http://10.31.60.18:8000/AuthorizationPeopleGetRout/api
                    url: 'http://10.31.60.18:8000/AuthorizationPeopleSetRout/api/Employee/AddEmployee',
                    type: 'post',
                    data: JSON.stringify(employeeform),
                    contentType: 'application/json',
                    success: function (res) {
                        if (res > 0) {
                            layer.alert('添加成功!');
                            location.href = '/Employee/ShowEmployee';
                        }
                        else {
                            layer.alert('添加失败！');
                        }
                    }
                })

                return false; // 阻止默认 form 跳转
            });

            // 普通事件
            util.on('lay-on', {
                // 获取验证码
                "get-vercode": function (othis) {
                    var isvalid = form.validate('.demo-phone'); // 主动触发验证，v2.7.0 新增
                    // 验证通过
                    if (isvalid) {
                        layer.msg('手机号规则验证通过');
                        // 此处可继续书写「发送验证码」等后续逻辑
                        // …
                    }
                }
            });

            //绑定部门下拉框
            $(document).ready(function () {
                $.ajax({
                    url: 'http://10.31.60.18:8000/AuthorizationGetRout/api/Cottage/DeparList',
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        var departDate = res;
                        var select = $('#departId');
                        $.each(departDate, function (index, item) {
                            var option = $('<option>').val(item.id).text(item.name);
                            select.append(option);
                        })
                        //手动触发 layui组件的渲染
                        layui.form.render('select');
                    },
                })
            })

            //绑定部门下拉框
            $(document).ready(function () {
                $.ajax({
                    url: 'http://10.31.60.18:8000/AuthorizationPeopleGetRout/api/RoleShow/BindRoleList',
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        var departDate = res;
                        var select = $('#roleId');
                        $.each(departDate, function (index, item) {
                            var option = $('<option>').val(item.id).text(item.name);
                            select.append(option);
                        })
                        //手动触发 layui组件的渲染
                        layui.form.render('select');
                    },
                })
            })

            //绑定单位下拉框
            $(document).ready(function () {
                $.ajax({
                    url: 'http://10.31.60.18:8000/AuthorizationGetRout/api/Cottage/UnitsList',
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        var departDate = res;
                        var select = $('#unitId');
                        $.each(departDate, function (index, item) {
                            var option = $('<option>').val(item.id).text(item.name);
                            select.append(option);
                        })
                        //手动触发 layui组件的渲染
                        layui.form.render('select');
                    },
                })
            })
        });
    </script>

</body>